package com.qst.mapreduce.wordcount.shujushengcheng;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class GameLogGenerator {

    private static final String[] provinces = {"山东", "广东", "湖南", "河南", "江苏", "浙江", "四川", "湖北", "福建", "安徽"};
    private static final Random random = new Random();

    public static void main(String[] args) {
        String filePath = "game_logs.txt"; // 输出文件路径
        int numberOfRecords = 1000000; // 生成记录的数量

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
            for (int i = 0; i < numberOfRecords; i++) {
                // 生成随机用户ID
                String userId = String.valueOf(100000000 + random.nextInt(900000000));
                // 随机选择省份
                String province = provinces[random.nextInt(provinces.length)];
                // 生成随机游戏开始时间
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String startTime = dateFormat.format(new Date(1632407401000L + (random.nextLong() % 31536000000L)));
                // 生成随机游戏时长
                int gameDuration = random.nextInt(60); // 假设游戏时长不超过60分钟
                // 随机是否通关
                int isPassed = random.nextInt(2);

                // 拼接日志记录
                String logRecord = String.format("%s,%s,%s,%d,%d\n", userId, province, startTime, gameDuration, isPassed);
                writer.write(logRecord);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
